using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Launcher
{
    public class DllLoaderHelper
    {
        /// <summary>
        /// 获取指定目录及其子目录中的所有 DLL 文件的绝对路径
        /// </summary>
        /// <param name="targetDirectory">目标目录（可以是相对或绝对路径）</param>
        /// <param name="searchOption">是否搜索子目录</param>
        /// <returns>包含所有 DLL 文件绝对路径的数组</returns>
        public static string[] GetAllDllFiles(string targetDirectory, SearchOption searchOption = SearchOption.AllDirectories)
        {
            // 确保目录路径是绝对路径
            string fullDirectoryPath = Path.GetFullPath(targetDirectory);

            // 检查目录是否存在
            if (!Directory.Exists(fullDirectoryPath))
            {
                throw new DirectoryNotFoundException($"目录不存在: {fullDirectoryPath}");
            }

            // 获取所有 DLL 文件，并转换为绝对路径
            var dllFiles = Directory.EnumerateFiles(
                fullDirectoryPath,
                "*.dll",
                searchOption)
                .Select(f => Path.GetFullPath(f))
                .ToArray();

            return dllFiles;
        }
    }
}